package fr.babos.test.perfs 
{
	import com.greensock.easing.Strong;
	import com.greensock.TweenMax;
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import fr.babos.graphic.components.base.ResizableComponent;
	import fr.babos.graphic.components.base.StageWrapper;
	import fr.babos.graphic.tools.AutoScaleNineBitmaps;
	import net.hires.debug.Stats;
	
	/**
	 * @author ZoulouX
	 */
	public class BitmapsSlicesPerfTest extends Sprite 
	{
		[Embed(source="../../../../../lib/graphics/autoScaleNineTest1.png")]
		public static const ImageSource1:Class;
		
		[Embed(source="../../../../../lib/graphics/autoScaleNineTest2.png")]
		public static const ImageSource2:Class;
		
		[Embed(source="../../../../../lib/graphics/ScrollBar.png")]
		public static const ScrollBarImage:Class;
		
		public function BitmapsSlicesPerfTest ()
		{
			if (stage != null)
				init();
			else
				addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		protected function init (e:Event = null):void
		{
			if (e != null)
				removeEventListener(Event.ADDED_TO_STAGE, init);
			
			var wrapper:StageWrapper = new StageWrapper(stage);
			
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			
			//var source:BitmapData = (new ImageSource1() as Bitmap).bitmapData;
			var source:BitmapData = (new ImageSource2() as Bitmap).bitmapData;
			//var source:BitmapData = (new ScrollBarImage() as Bitmap).bitmapData;
			
			//var asn2:AutoScaleNine2 = new AutoScaleNineBitmaps(source).place(10, 10, 10, 10).into(wrapper, "asn2") as AutoScaleNineBitmaps;
			//var asn2:AutoScaleNine2 = new AutoScaleNineBitmaps(source).place(10, NaN, NaN, 10).setSize(32, 32).into(wrapper, "asn2") as AutoScaleNineBitmaps;
			//var verticalScrollBar:AutoScaleNine2 = new AutoScaleNineBitmaps(source).place(10, 10, 10).setSize(8, NaN).into(wrapper) as AutoScaleNineBitmaps;
			//var horizontalScrolBar:AutoScaleNine2 = new AutoScaleNineBitmaps(source).place(NaN, 10, 10, 10).setSize(NaN, 8).into(wrapper) as AutoScaleNineBitmaps;
			
			
			for (var i:int = 0; i < 10; i++) 
			{
				var scroll:ResizableComponent = new AutoScaleNineBitmaps(source).place(10 + i * 50, NaN, NaN, 10).size(8, 8).into(wrapper);
				
				scroll.scaleX = scroll.scaleY = .5;
				
				scroll.width = 60;
				
				TweenMax.to(scroll, .5 + Math.random() * 2, {
					yoyo: true,
					delay: Math.random() * 2,
					repeat: 100,
					ease: Strong.easeInOut,
					width: 600
				});
			}
			
			//wrapper.addChild(new Stats());
		}
	}
}